/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AdminRoom.java
 *
 * Created on Apr 30, 2012, 5:38:08 PM
 */
package GUI.Admin;

import dao.PhongChieuDAO;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.Vector;
import javax.swing.ActionMap;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.application.Action;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.Task;
import pojo.Phongchieu;
import utils.BusyIndicator;
import utils.BusyIndicatorInputBlocker;
import utils.ClassUtils;

/**
 *
 * @author Hnmtuan
 */
public class AdminRoom extends javax.swing.JPanel {

    // <editor-fold defaultstate="collapsed" desc="Define all variables using this application">
    private SingleFrameApplication localApplication;
    private DefaultTableModel _showTimesModel;
    private BusyIndicator localBusy;
    private ActionMap _rsActionMap;
    private List<Phongchieu> _rooms;
    private boolean saveNeeded, cancelSelected, newRow;
    private String DEFAULT_SEARCH_STRING;
    // </editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Define messages and error messages" >
    private final String MSG_EMPTY = "";
    private final String ERR_LIST_EMPTY = "Room list is empty";
    private final String MSG_LOADING = "Reloading list rooms  .... !";
    private final String MSG_SAVE_SUCCESS = "Insert film successfully";
    private final String MSG_SAVE_BEGINNING = "Begin saving .... !";
    private final String MSG_SAVE_DATABASE = "Saving database  .... !";
    private final String MSG_UPDATE_SUCCESS = "Update film successfully";
    private final String MSG_UPDATE_BEGINNING = "Begin updating .... !";
    private final String MSG_UPDATE_DATABASE = "Updating database  .... !";
    private final String MSG_DELETE_SUCCESS = "Delete film type successfully";
    private final String MSG_DELETE_BEGINNING = "Begin deleteing .... !";
    private final String MSG_DELETE_DATABASE = "Deleteing database  .... !";
    private final String MSG_DELETE_CONFIRM = "Do you want to delete %s ?";
    private final String MSG_DELETE_TITLE = "Delete Film Type";
    private final String MSG_SEARCH_BEGINNING = "Begin searching .... !";
    private final String MSG_SEARCH_SUCCESS = "Search successfully .... !";
    private final String ERR_SAVE_TASK = "Save task not done !";
    private final String ERR_SELECT_OUTOFBOUND = "You select out of bound !";
    private final String ERR_SELECTED_TYPE_EMPTY = "Selected room is empty";
    private final String ERR_UPDATE_INVALID_PARAMS = "Update invalid parameters !";
    private final String ERR_UPDATE_TASK = "Update task not done !";
    private final String ERR_DELETE_INVALID_PARAMS = "Delete invalid parameters !";
    private final String ERR_DELETE_TASK = "Delete task not done !";
    private final String ERR_SEARCH_INVALID_PARAMS = "Search invalid parameters !";
    private final String ERR_SEARCH_INVALID_SOURCES = "Source search empty !";
    private final String ERR_SEARCH_NOT_FOUND = "%s not found !";
    private final String ERR_SEARCH_TASK = "Search task not done !";
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Constructor" >

    public AdminRoom(SingleFrameApplication appContext, BusyIndicator busy) throws Exception {
        localApplication = appContext;
        localBusy = busy;
        initComponents();
        initActions();
        loadRooms();
    }
// </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Init Actions" >

    private void initActions() throws Exception {
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("GUI/Admin/resources/AdminRoom");
        _rsActionMap = Application.getInstance(main.MainFormApp.class).getContext().getActionMap(getClass(), this);
        jbtnSearch.setAction(_rsActionMap.get("searchFilms"));
        jbtnReset.setAction(_rsActionMap.get("resetRow"));
        jbtnAdd.setAction(_rsActionMap.get("addRow"));
        jbtnUpdate.setAction(_rsActionMap.get("updateRow"));
        jbtnDelete.setAction(_rsActionMap.get("deleteRow"));
        jbtnCancel.setAction(_rsActionMap.get("cancelRow"));
        setNewRow(true);
        DEFAULT_SEARCH_STRING = bundle.getString("jtfSearchRoom.title");
        jtbRooms.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            // -->>> not revoiked event throws exception

            public void valueChanged(ListSelectionEvent e) {
                if (isRecordSelected()) {
                    loadFields();
                }
                firePropertyChange("recordSelected", !isRecordSelected(), isRecordSelected());
                setSaveNeeded(true);
                setCancelSelected(true);
                setNewRow(false);
            }
        });
        jtfSearch.addMouseListener(new MouseAdapter() {

            // Compsite of two actions Press and Release
            @Override
            public void mouseClicked(MouseEvent e) {
                String searchText = jtfSearch.getText();
                // if text field empty so on ...
                if (searchText.equalsIgnoreCase(DEFAULT_SEARCH_STRING)) {
                    jtfSearch.setText(MSG_EMPTY);
                }
            }

            @Override
            public void mouseExited(MouseEvent e) {
                String searchText = jtfSearch.getText();
                // if texfield empty so write default text for it
                if (searchText.equalsIgnoreCase("")) {
                    jtfSearch.setText(DEFAULT_SEARCH_STRING);
                }
                // else nothing else ..
            }
        });
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Implement All Actions">

    @Action
    public Task searchFilms() {
        Task task = new SearchTask();
        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action
    public void resetRow() {
        clearAllTextField();
    }

    @Action(enabledProperty = "newRow")
    public Task addRow() {
        Task task = new SaveTask();
        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action(enabledProperty = "saveNeeded")
    public Task updateRow() {
        Task task = new UpdateTask();
        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action(enabledProperty = "recordSelected")
    public Task deleteRow() {
        Task task = new DeleteTask();
        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action(enabledProperty = "cancelSelected")
    public void cancelRow() {
        clearAllTextField();
        defaultButtonState();
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Implement All Property or State">

    public boolean isNewRow() {
        return newRow;
    }

    public void setNewRow(boolean newRow) {
        if (newRow != this.newRow) {
            this.newRow = newRow;
            firePropertyChange("newRow", !this.newRow, this.newRow);
        }
    }

    public boolean isSaveNeeded() {
        return saveNeeded;
    }

    public void setSaveNeeded(boolean saveNeeded) {
        if (saveNeeded != this.saveNeeded) {
            this.saveNeeded = saveNeeded;
            firePropertyChange("saveNeeded", !this.saveNeeded, this.saveNeeded);
        }
    }

    public boolean isRecordSelected() {
        return jtbRooms.getSelectedRow() != -1;
    }

    public boolean isCancelSelected() {
        return cancelSelected;
    }

    public void setCancelSelected(boolean cancelSelected) {
        if (cancelSelected != this.cancelSelected) {
            this.cancelSelected = cancelSelected;
            firePropertyChange("cancelSelected", !this.cancelSelected, this.cancelSelected);
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Implement Actions to GUI" >

    protected final void setSelectedRowShowTime(int index) {
        if (index == -1) {
            return;
        }
        jtbRooms.changeSelection(index, 0, false, false);
    }

    protected final int getRoomByCode(String code) throws Exception {
        if (code.isEmpty()) {
            throw new Exception(ERR_SEARCH_INVALID_PARAMS);
        }
        if (_rooms == null || _rooms.size() < 1) {
            throw new Exception(ERR_SEARCH_INVALID_SOURCES);
        }
        int searchIndex = -1;
        int maxSize = _rooms.size();
        for (Phongchieu item : _rooms) {
            searchIndex++;
            if (item.getCodePhong().equalsIgnoreCase(code)) {
                return searchIndex;
            }
        }
        return searchIndex = (searchIndex == maxSize - 1) ? -1 : searchIndex;
    }

    protected final int getRoomByName(String name) throws Exception {
        if (name.isEmpty()) {
            throw new Exception(ERR_SEARCH_INVALID_PARAMS);
        }
        if (_rooms == null || _rooms.size() < 1) {
            throw new Exception(ERR_SEARCH_INVALID_SOURCES);
        }
        int searchIndex = -1;
        int maxSize = _rooms.size();
        for (Phongchieu item : _rooms) {
            searchIndex++;
            if (item.getTenPhong().equalsIgnoreCase(name)) {
                return searchIndex;
            }
        }
        return searchIndex = (searchIndex == maxSize - 1) ? -1 : searchIndex;
    }

    protected final void loadFields() {
        try {
            if (_rooms == null) {
                throw new Exception(ERR_LIST_EMPTY);
            }
            int maxSize = _rooms.size();
            int selectedRow = jtbRooms.getSelectedRow(); //row which you select into JTable
            if (selectedRow > maxSize) {
                throw new Exception(ERR_SELECT_OUTOFBOUND);
            }
            Phongchieu selectedRoom = _rooms.get(selectedRow);
            if (selectedRoom == null) {
                throw new Exception(ERR_SELECTED_TYPE_EMPTY);
            }
            jtfCodeRoom.setText(selectedRoom.getCodePhong());
            jtfNameRoom.setText(selectedRoom.getTenPhong());
            jtfSeatRoom.setText(selectedRoom.getSoLuongCho().toString());
            jtfLineRoom.setText(selectedRoom.getSoLuongHangGhe().toString());
            jtfColumnRoom.setText(selectedRoom.getSoLuongCot().toString());
        } catch (Exception e) {
            //System.out.println(String.format("Error: %s", e.getMessage()));
            e.printStackTrace(); //-->>> show remove this code
        }
    }

    protected final void defaultButtonState() {
        jtbRooms.clearSelection();
        firePropertyChange("recordSelected", isRecordSelected(), !isRecordSelected());
        setSaveNeeded(false);
        setCancelSelected(false);
        setNewRow(true);
    }

    protected final void clearAllTextField() {
        jtfCodeRoom.setText(MSG_EMPTY);
        jtfNameRoom.setText(MSG_EMPTY);
        jtfSeatRoom.setText(MSG_EMPTY);
        jtfLineRoom.setText(MSG_EMPTY);
        jtfColumnRoom.setText(MSG_EMPTY);
    }

    protected final void loadRooms() throws Exception {
        _showTimesModel = (DefaultTableModel) jtbRooms.getModel();
        _showTimesModel.getDataVector().clear();
        try {
            _rooms = PhongChieuDAO.getPhongChieus();
            if (_rooms == null) {
                throw new Exception(ERR_LIST_EMPTY);
            }
            int count = 0;
            for (Phongchieu room : _rooms) {
                Vector v = new Vector();
                count = count + 1;
                v.addElement(count);
                v.addElement(room.getCodePhong());
                v.addElement(room.getTenPhong());
                v.addElement(room.getSoLuongCho());
                _showTimesModel.addRow(v);
            }
            jtbRooms.setModel(_showTimesModel);
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        } finally {
            PhongChieuDAO.closeCurrentSession();
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Search Task">

    private class SearchTask extends Task<Void, Void> {

        public SearchTask() {
            super(localApplication);
        }

        @Override
        protected Void doInBackground() throws Exception {
            setMessage(MSG_SEARCH_BEGINNING);
            Thread.sleep(150L);
            setProgress(1, 0, 3);
            // Check text field to input text not empty or default text
            String searchField = jtfSearch.getText();
            int resultIndex = -1;
            // Check option search to be checked
            if (jrdByCode.isSelected()) {
                resultIndex = getRoomByCode(searchField);
            } else if (jrdByName.isSelected()) {
                resultIndex = getRoomByName(searchField);
            }
            // Get object is selected
            if (resultIndex == -1) {
                throw new Exception(String.format(ERR_SEARCH_NOT_FOUND, searchField));
            }
            // Search database
            setSelectedRowShowTime(resultIndex);
            // Loading GUI
            setMessage(MSG_LOADING);
            Thread.sleep(150L);
            setProgress(2, 0, 3);
            return null;
        }

        @Override
        protected void cancelled() {
            setMessage(ERR_SEARCH_TASK);
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
            clearAllTextField();
            defaultButtonState();
        }

        @Override
        protected void succeeded(Void t) {
            setMessage(MSG_SEARCH_SUCCESS);
            setProgress(3, 0, 3);
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Delete Task" >

    private class DeleteTask extends Task<Void, Void> {

        public DeleteTask() {
            super(localApplication);
        }

        @Override
        protected Void doInBackground() throws Exception {
            setMessage(MSG_DELETE_BEGINNING);
            Thread.sleep(150L);
            setProgress(1, 0, 4);
            // Get object is selected to delete
            int selectedIndex = jtbRooms.getSelectedRow();
            if (_rooms == null || selectedIndex == -1) {
                throw new Exception(ERR_DELETE_INVALID_PARAMS);
            }
            Phongchieu cachedRoom = _rooms.get(selectedIndex);
            String msg = String.format(MSG_DELETE_CONFIRM, cachedRoom.getCodePhong());
            int returnOptionDialog = JOptionPane.showConfirmDialog(localApplication.getMainFrame(), msg, MSG_DELETE_TITLE, JOptionPane.OK_CANCEL_OPTION);
            if (returnOptionDialog == JOptionPane.CANCEL_OPTION) {
                return null;
            }
            setMessage(MSG_DELETE_DATABASE);
            Thread.sleep(150L);
            setProgress(2, 0, 4);
            // Delete database
            PhongChieuDAO.deletePhongChieus(cachedRoom);
            // Loading GUI
            setMessage(MSG_LOADING);
            Thread.sleep(150L);
            setProgress(3, 0, 4);
            loadRooms();
            Thread.sleep(150L);
            return null;
        }

        @Override
        protected void cancelled() {
            setMessage(ERR_DELETE_TASK);
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
        }

        @Override
        protected void succeeded(Void t) {
            clearAllTextField();
            defaultButtonState();
            setMessage(MSG_DELETE_SUCCESS);
            setProgress(4, 0, 4);
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Update Task" >

    private class UpdateTask extends Task<Void, Void> {

        public UpdateTask() {
            super(localApplication);
        }

        @Override
        protected Void doInBackground() throws Exception {
            setMessage(MSG_UPDATE_BEGINNING);
            Thread.sleep(150L);
            setProgress(1, 0, 4);
            // Get information and prepare object
            int selectedIndex = jtbRooms.getSelectedRow();
            if (_rooms == null || selectedIndex == -1) {
                throw new Exception(ERR_UPDATE_INVALID_PARAMS);
            }
            Phongchieu cachedRoom = _rooms.get(selectedIndex);

            String codeRoom = jtfCodeRoom.getText();
            String nameRoom = jtfNameRoom.getText();
            String seatRoom = jtfSeatRoom.getText();
            String lineRoom = jtfLineRoom.getText();
            String columnRoom = jtfColumnRoom.getText();


            cachedRoom.setCodePhong(codeRoom);
            cachedRoom.setTenPhong(nameRoom);
            cachedRoom.setSoLuongCho(Integer.parseInt(seatRoom));
            cachedRoom.setSoLuongHangGhe(Integer.parseInt(lineRoom));
            cachedRoom.setSoLuongCot(Integer.parseInt(columnRoom));

            setMessage(MSG_UPDATE_DATABASE);
            Thread.sleep(150L);
            setProgress(2, 0, 4);
            // Update to database
            PhongChieuDAO.updatePhongChieus(cachedRoom);
            // Loading gui
            setMessage(MSG_LOADING);
            Thread.sleep(150L);
            setProgress(3, 0, 4);
            loadRooms();
            Thread.sleep(150L);
            return null;
        }

        @Override
        protected void cancelled() {
            setMessage(ERR_UPDATE_TASK);
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
        }

        @Override
        protected void succeeded(Void t) {
            clearAllTextField();
            defaultButtonState();
            setMessage(MSG_UPDATE_SUCCESS);
            setProgress(4, 0, 4);
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Save Task" >

    private class SaveTask extends Task<Void, Void> {

        public SaveTask() {
            super(localApplication);
        }

        @Override
        protected Void doInBackground() throws Exception {
            setMessage(MSG_SAVE_BEGINNING);
            Thread.sleep(150L);
            setProgress(1, 0, 4);
            // Get all information from fields
            String codeRoom = jtfCodeRoom.getText();
            String nameRoom = jtfNameRoom.getText();
            String seatRoom = jtfSeatRoom.getText();
            String lineRoom = jtfLineRoom.getText();
            String columnRoom = jtfColumnRoom.getText();

            // Prepare object
            Phongchieu room = new Phongchieu(codeRoom, nameRoom, Integer.parseInt(seatRoom),
                    Integer.parseInt(lineRoom), Integer.parseInt(columnRoom), ClassUtils.StateFields.DEFAULT_STATUS,
                    null, null);
            setMessage(MSG_SAVE_DATABASE);
            Thread.sleep(150L);
            setProgress(2, 0, 4);
            // Save into database
            PhongChieuDAO.insertPhongChieus(room);
            setMessage(MSG_LOADING);
            Thread.sleep(150L);
            setProgress(3, 0, 4);
            loadRooms();
            Thread.sleep(150L);
            return null;
        }

        @Override
        protected void cancelled() {
            setMessage(ERR_SAVE_TASK);
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
        }

        @Override
        protected void succeeded(Void t) {
            setMessage(MSG_SAVE_SUCCESS);
            setProgress(4, 0, 4);
            clearAllTextField();
            defaultButtonState();
        }
    }
    // </editor-fold>

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnGroupOptions = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jtfSearch = new javax.swing.JTextField();
        jbtnSearch = new javax.swing.JButton();
        jrdByCode = new javax.swing.JRadioButton();
        jrdByName = new javax.swing.JRadioButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbRooms = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtfCodeRoom = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtfNameRoom = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jtfSeatRoom = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jtfLineRoom = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jtfColumnRoom = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jbtnReset = new javax.swing.JButton();
        jbtnAdd = new javax.swing.JButton();
        jbtnUpdate = new javax.swing.JButton();
        jbtnDelete = new javax.swing.JButton();
        jbtnCancel = new javax.swing.JButton();

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("GUI/Admin/resources/AdminRoom"); // NOI18N
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("jpSearchForm.title"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jtfSearch.setText(bundle.getString("jtfSearchRoom.title")); // NOI18N
        jtfSearch.setName("jtfSearch"); // NOI18N

        jbtnSearch.setText(bundle.getString("jbtnSearch.title")); // NOI18N
        jbtnSearch.setName("jbtnSearch"); // NOI18N

        btnGroupOptions.add(jrdByCode);
        jrdByCode.setSelected(true);
        jrdByCode.setText(bundle.getString("jrdCodeRoom.title")); // NOI18N
        jrdByCode.setName("jrdByCode"); // NOI18N

        btnGroupOptions.add(jrdByName);
        jrdByName.setText(bundle.getString("jrdNameRoom.title")); // NOI18N
        jrdByName.setName("jrdByName"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(67, 67, 67)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jrdByCode)
                        .addGap(29, 29, 29)
                        .addComponent(jrdByName))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jtfSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 348, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(86, 86, 86)
                        .addComponent(jbtnSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(68, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnSearch))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jrdByCode)
                    .addComponent(jrdByName))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("jpListRoom.title"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jtbRooms.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nums", "Code", "Name", "Seats"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtbRooms.setName("jtbRooms"); // NOI18N
        jtbRooms.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jtbRooms);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 708, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("jpRoomDetailForm.title"))); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N

        jLabel1.setText(bundle.getString("jlbCodeRoom.title")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jtfCodeRoom.setName("jtfCodeRoom"); // NOI18N

        jLabel2.setText(bundle.getString("jlbNameRoom.title")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jtfNameRoom.setName("jtfNameRoom"); // NOI18N

        jLabel3.setText(bundle.getString("jlbNumsSeat.title")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jtfSeatRoom.setName("jtfSeatRoom"); // NOI18N

        jLabel4.setText(bundle.getString("jlbLineSeat.title")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jtfLineRoom.setName("jtfLineRoom"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(AdminRoom.class);
        jLabel5.setText(resourceMap.getString("jlbColumnSeat.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jtfColumnRoom.setName("jtfColumnRoom"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(163, 163, 163)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jtfSeatRoom, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addComponent(jLabel2)
                            .addGap(98, 98, 98)
                            .addComponent(jtfNameRoom, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addGap(98, 98, 98)
                            .addComponent(jtfCodeRoom, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 95, Short.MAX_VALUE)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtfColumnRoom)
                            .addComponent(jtfLineRoom, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE))))
                .addContainerGap(174, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfCodeRoom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfNameRoom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfSeatRoom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jtfLineRoom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jtfColumnRoom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("jpAction.title"))); // NOI18N
        jPanel4.setName("jPanel4"); // NOI18N

        jbtnReset.setText(bundle.getString("jbtnReset.title")); // NOI18N
        jbtnReset.setName("jbtnReset"); // NOI18N

        jbtnAdd.setText(bundle.getString("jbtnAddRoom.title")); // NOI18N
        jbtnAdd.setName("jbtnAdd"); // NOI18N

        jbtnUpdate.setText(bundle.getString("jbtnUpdateRoom.title")); // NOI18N
        jbtnUpdate.setName("jbtnUpdate"); // NOI18N

        jbtnDelete.setText(bundle.getString("jbtnDeleteRoom.title")); // NOI18N
        jbtnDelete.setName("jbtnDelete"); // NOI18N

        jbtnCancel.setText(bundle.getString("jbtnCancel.title")); // NOI18N
        jbtnCancel.setName("jbtnCancel"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(90, 90, 90)
                .addComponent(jbtnReset, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addComponent(jbtnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(jbtnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(jbtnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addComponent(jbtnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(91, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnReset)
                    .addComponent(jbtnAdd)
                    .addComponent(jbtnUpdate)
                    .addComponent(jbtnDelete)
                    .addComponent(jbtnCancel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup btnGroupOptions;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtnAdd;
    private javax.swing.JButton jbtnCancel;
    private javax.swing.JButton jbtnDelete;
    private javax.swing.JButton jbtnReset;
    private javax.swing.JButton jbtnSearch;
    private javax.swing.JButton jbtnUpdate;
    private javax.swing.JRadioButton jrdByCode;
    private javax.swing.JRadioButton jrdByName;
    private javax.swing.JTable jtbRooms;
    private javax.swing.JTextField jtfCodeRoom;
    private javax.swing.JTextField jtfColumnRoom;
    private javax.swing.JTextField jtfLineRoom;
    private javax.swing.JTextField jtfNameRoom;
    private javax.swing.JTextField jtfSearch;
    private javax.swing.JTextField jtfSeatRoom;
    // End of variables declaration//GEN-END:variables
}
